package JAVA300.第十章IO;

import java.io.*;

/**
 * 学习处理流之-数据流
 */

public class IO_Study13_DataInputStream {
    public static void main(String[] args) {

        //写出
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dataOutputStream = new DataOutputStream(new BufferedOutputStream(baos));
        try {
            dataOutputStream.writeUTF("hqqQYH");
            dataOutputStream.writeInt(18);
            dataOutputStream.writeChar('q');
            dataOutputStream.flush();
            byte[] datas = baos.toByteArray();
            System.out.println(datas.length);//可以计算出占用字节

            //读取
            DataInputStream dataInputStream = new DataInputStream(new BufferedInputStream(new ByteArrayInputStream(datas)));
            String msg = dataInputStream.readUTF();
            int msg1 = dataInputStream.readInt();
            char msg2 = dataInputStream.readChar();
            System.out.println(msg);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
